package tree;

import graph.Vertex;

import java.util.ArrayList;
import java.util.List;

public class Node {
	/**
	 * @uml.property  name="label" multiplicity="(0 -1)" dimension="1"
	 */
	String[] label;
	/**
	 * @uml.property  name="elements"
	 */
	List<Vertex> elements;
	
	public Node(String[] label){
		this.label = label;
		this.elements = new ArrayList<Vertex>();
	}
	
	public int getBagSize(){
		return (this.elements != null ? this.elements.size() : 0);
	}
	
	public void setElements(List<Vertex> l){
		this.elements = new ArrayList<Vertex>(l);
	}
	
	public String printElements(){
		return this.toString() + (this.elements.size() > 0 ? this.elements : "");
	}
	
	public String toString(){
		StringBuffer strbuff = new StringBuffer();
		for (int i = 0; i < label.length; i++) {
			if(strbuff.length()>0)
				strbuff.append(";".concat(label[i]));
			else
				strbuff.append(label[i]);
		}
		return strbuff.toString();
	}
	@Override
	public boolean equals(Object o) {
		Node n = (Node) o;
		boolean contain;
		for (int i = 0; i < this.label.length; i++) {
			contain = false;
			for (int j = 0; j < n.label.length; j++) {
				if(this.label[i].contentEquals(n.label[j])){
					contain=true;
					break;
				}
			}
			if(contain==false)
				return false;
		}
		return true;
	}
}
